package host.skiree.nettydemo.client.service.impl;

import host.skiree.nettydemo.client.service.MessageClientHandler;
import host.skiree.nettydemo.message.GroupChatResponseMessage;
import host.skiree.nettydemo.message.Message;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author gcl
 * @date 2022/9/21 8:45
 */
public class GroupChat implements MessageClientHandler {
    @Override
    public void handleMessage(ChannelHandlerContext ctx, Message message) {
        GroupChatResponseMessage groupChatResponseMessage = (GroupChatResponseMessage) message;
        if ( groupChatResponseMessage.isSuccess() ){
            String flag = groupChatResponseMessage.getFrom();
            String text = groupChatResponseMessage.getContent();
            System.out.printf("来自聊天室 %s 的消息 : %s\n", flag, text);
        }else {
            System.out.println(groupChatResponseMessage.getReason());
        }
    }
}
